import axios from "axios"
export default {	
   data(){
    	return{
    		cartfoods:[],
    		totalprice:0
    	}
   },
    mounted(){ 
	   	axios.get('/api/yidiancaiping').then((res) => {	 
  			//console.log(res.data);
			this.cartfoods=res.data;
			console.log(this.cartfoods);
			this.numbers=0;
			this.totalprice=0;
			for (var i=0;i<this.cartfoods.length;i++){					
				var price=this.cartfoods[i].cpjg;
				var number=Number(this.cartfoods[i].ydfs);
				//console.log(i);
				//console.log(number);
				this.totalprice +=price*number;				
			}
		});	
  	},
  	 methods: {
  	 	pay:function() {
  	 		axios.get('/wxpay/pay').then((r) => {
  	 			WeixinJSBridge.invoke('getBrandWCPayRequest', r,
						function(res) {
							//支付成功或失败前台判断
							if(res.err_msg == 'get_brand_wcpay_request:ok') {
								alert('恭喜您，支付成功!');
							} else {
								alert('支付失败');
							}
						});
  	 			
  	 		});
  	 	}
  	 		
  	 }
}